package com.lboyang.seckill.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: RabbitMQ配置类
 * @Author: Aiguodala
 * @CreateDate: 2021/5/30 11:16
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 队列
     */
    private static final String QUEUE = "seckillQueue";

    /**
     * 交换机
     */
    private static final String EXCHANGE = "seckillExchange";

    /**
     * 队列bean
     * @return
     */
    @Bean
    public Queue queue() {
        return new Queue(QUEUE);
    }

    /**
     * Topic交换机可以通过* # 等路由key匹配队列
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(EXCHANGE);
    }

    /**
     * 给队列绑定交换机
     * @return
     */
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(topicExchange()).with("seckill.#");
    }


}
